package logic

import (
	"context"
	"goods_srv/models/es"
	"goods_srv/models/mysql"

	"goods_srv/goodssrv"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsToEsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsToEsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsToEsLogic {
	return &GoodsToEsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsToEsLogic) GoodsToEs(in *goodssrv.GoodsToEsRequest) (*goodssrv.GoodsToEsResponse, error) {
	// todo: 同步商品到Es
	var goods []mysql.Goods
	mysql.DB.Debug().Find(&goods)
	es.SyncGoods(goods)
	return &goodssrv.GoodsToEsResponse{}, nil
}
